package com.david4.jizhang.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.david4.jizhang.common.BaseController;
import com.david4.jizhang.model.Consume;

/**
 * 
 * @author <a href="mailto:hanxiaojun85@gmail.com">hanxiaojun</a>
 * @since 2010-5-10
 */
@Controller
public class ConsumeController extends BaseController{
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/list.jhtml")
	public String list(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		Consume consume = new Consume();
		List<Consume> consumeList = (List)consume.find();
//		if(consumeList != null && consumeList.size() > 0 ){
//			for(Consume c : consumeList){
//				System.out.println(c.getId()+"=="+c.getPrice()+"=="+c.getDescribe()+"=="+c.getConDate());
//			}
//		}
		model.addAttribute("consumeList", consumeList);
		return "test";
	}
	
	@RequestMapping(value = "/input.jhtml")
	public String input(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		
		return "input";
	}
	
	@RequestMapping(value = "/save.jhtml",params={"price","describe","conDate"})
	public String save(Consume consume,HttpServletRequest request,
			HttpServletResponse response, Model model) {
		consume.save();
		
		
		return "input";
	}
	
	@RequestMapping(value = "/delete.jhtml",params={"id"})
	public String delete(Consume consume,HttpServletRequest request,
			HttpServletResponse response, Model model) {
		consume.delete(consume.getId());
		//model.addAttribute("result", 1);
		//return RESULTPAGE;
		return "redirect:/list.jhtml";
	}
}
